package cj.web.lkg.dao;

import java.util.List;
import java.util.Map;

import net.paoding.rose.jade.annotation.DAO;
import net.paoding.rose.jade.annotation.SQL;
import net.paoding.rose.jade.annotation.SQLParam;

@DAO
public interface NewsDAO {
	
	@SQL("SELECT id,title,isComments,columnsId FROM News WHERE id =:1 ")
	List<Map> queryNewsSize(int newsId);
	
	//头条
	@SQL("SELECT id,type,columnsId,title,subjectId,abstractInfor,content,carouselImage,releaseAt,label,isOuterLink,outerLinkUrl,vedioUrl FROM News WHERE deleteFlag=1 AND releaseState=2 AND releaseAt < NOW() AND isTop=1 AND columnsId=:1 ORDER BY stickAt DESC,releaseAt DESC LIMIT 0,3")
	List<Map> queryTopByColumnsId(int columnsId);
	
	//新闻列表 上拉加载 与上一次下拉刷新比较
	@SQL("SELECT id,type,columnsId,title,subjectId,abstractInfor,content,carouselImage,releaseAt,label,isOuterLink,outerLinkUrl,vedioUrl FROM News WHERE deleteFlag=1 AND releaseState=2 AND releaseAt <:5 #if(:ids!='[]'){ AND id NOT IN (:ids) } AND columnsId=:2 ORDER BY stickAt DESC,releaseAt DESC LIMIT :3,:4")
	List<Map> queryNewsByColumnsId(@SQLParam("ids")List<Integer> ids, int columnsId, int start, int length,String releaseAt);
	
	//新闻列表 上拉加载 size 与上一次下拉刷新比较
	@SQL("SELECT count(1) FROM News WHERE deleteFlag=1 AND releaseState=2 AND releaseAt<:3 #if(:ids!='[]'){ AND id NOT IN (:ids) } AND columnsId=:2 ")
	int querySizeByColumnsId(@SQLParam("ids")List<Integer> ids, int columnsId,String releaseAt);

	//新闻列表 上拉加载
	@SQL("SELECT id,type,columnsId,title,subjectId,abstractInfor,content,carouselImage,releaseAt,label,isOuterLink,outerLinkUrl,vedioUrl FROM News WHERE deleteFlag=1 AND releaseState=2 AND releaseAt < NOW() #if(:ids!='[]'){ AND id NOT IN (:ids) } AND columnsId=:2 ORDER BY stickAt DESC,releaseAt DESC LIMIT :3,:4")
	List<Map> queryNewsByColumnsId(@SQLParam("ids")List<Integer> ids, int columnsId, int start, int length);
	
	//新闻列表 上拉加载size
	@SQL("SELECT count(1) FROM News WHERE deleteFlag=1 AND releaseState=2 AND releaseAt<NOW() #if(:ids!='[]'){ AND id NOT IN (:ids) } AND columnsId=:2")
	int querySizeByColumnsId(@SQLParam("ids")List<Integer> ids, int columnsId);
	
	@SQL("select id,columnsId,title,keywords,abstractInfor,vedioUrl,carouselImage,content,source,author,releaseAt,isOuterLink,isComments,outerLinkUrl,praiseNum,commentsNum,collectNum,voteId from News where id=:1")
	List<Map> queryById(int id);

	//图文新闻 相关阅读列表
	@SQL("SELECT id,type,columnsId,title,subjectId,abstractInfor,content,carouselImage,releaseAt,label,isOuterLink,outerLinkUrl,vedioUrl,source FROM News WHERE deleteFlag=1 AND releaseState=2 AND releaseAt < NOW() and keywords like '%##(:1)%' and id!=:2 ORDER BY stickAt DESC,releaseAt DESC LIMIT 0,3")
	List<Map> queryByKeyWord(String keyWord,int id);

	//专题列表 上拉加载
	@SQL("SELECT id,type,title,abstractInfor,content,carouselImage,releaseAt,label,isOuterLink,outerLinkUrl,vedioUrl FROM News WHERE deleteFlag=1 AND releaseState=2 AND :5 < releaseAt < NOW() AND subjectId=:1 AND columnsId=:2 ORDER BY stickAt DESC,releaseAt DESC LIMIT :3,:4")
	List<Map> queryNewsBySublectId(int subjectId, int columnsId, int start,	int length,String releaseAt);
	
	//专题列表 上拉加载size
	@SQL("SELECT count(1) FROM News WHERE deleteFlag=1 AND releaseState=2 AND :3 < releaseAt < NOW() AND subjectId=:1 AND columnsId=:2")
	int querySizeBySublectId(int subjectId, int columnsId,String releaseAt);

	//新闻列表 下拉刷新
	@SQL("SELECT id,type,columnsId,title,subjectId,abstractInfor,content,carouselImage,releaseAt,label,isOuterLink,outerLinkUrl,vedioUrl FROM News WHERE deleteFlag=1 AND releaseState=2 AND :3<releaseAt AND releaseAt<NOW() #if(:ids!='[]'){ AND id NOT IN (:ids) } AND columnsId=:2 ORDER BY stickAt DESC,releaseAt DESC LIMIT 0,5")
	List<Map> queryNewsByLastDate(@SQLParam("ids")List<Integer> ids, int columnsId, String releaseAt);

	//新闻列表 下拉刷新size
	@SQL("SELECT count(1) FROM News WHERE deleteFlag=1 AND releaseState=2 AND :3<releaseAt AND releaseAt<NOW() #if(:ids!='[]'){ AND id NOT IN (:ids) } AND columnsId=:2  ")
	int querySizeByLastDate(@SQLParam("ids")List<Integer> ids, int columnsId, String releaseAt);

	//专题列表 下拉刷新
	@SQL("SELECT id,type,title,abstractInfor,content,carouselImage,releaseAt,label,isOuterLink,outerLinkUrl,vedioUrl FROM News WHERE deleteFlag=1 AND releaseState=2 AND :3<releaseAt AND releaseAt<NOW() AND subjectId=:1 AND columnsId=:2 ORDER BY stickAt DESC,releaseAt DESC")
	List<Map> queryNewsByNewestId(int subjectId, int columnsId, String releaseAt);

	//专题列表 下拉刷新size
	@SQL("SELECT count(1) FROM News WHERE deleteFlag=1 AND releaseState=2 AND :3<releaseAt AND releaseAt<NOW() AND subjectId=:1 AND columnsId=:2")
	int querySizeByNewestId(int subjectId, int columnsId, String releaseAt);

	//专题的描述
	@SQL("select id as subjectId,name,carouselImage,descs from Subject where id=:1")
	List<Map> querySubjectById(int subjectId);

	//新闻搜索列表 上拉加载
	@SQL("SELECT id,type,columnsId,title,subjectId,abstractInfor,content,carouselImage,releaseAt,label,isOuterLink,outerLinkUrl,vedioUrl FROM News WHERE deleteFlag=1 AND releaseState=2 AND title LIKE '%##(:1)%' ORDER BY stickAt DESC,releaseAt DESC LIMIT :2,:3")
	List<Map> queryNewsByKeyword(String keyword,int start, int length);

	@SQL("SELECT count(1) FROM News WHERE deleteFlag=1 AND releaseState=2 AND title LIKE '%##(:1)%' ")
	int querySizeByKeyword(String keyword);

	@SQL("select id,isLogin from vote where deleteFlag=1 and id=:1")
	List<Map> getVoteById(int voteId);

	@SQL("select id,subject,isMutil,count from voteSubject where deleteFlag=1 and voteId=:1 ORDER BY stickAt DESC,createAt ASC")
	List<Map> getSubjByVoteId(int voteId);

	@SQL("select id,subjectId,item,count from voteItem where deleteFlag=1 and subjectId=:1 ORDER BY orderNum")
	List<Map> getItmBySubId(int subId);

	@SQL("select COUNT(1) from voteLog where deleteFlag=1 and voteId=:1 and devicesId=:2")
	int voteLogCnt(int voteId, String devicesId);

	@SQL("INSERT INTO voteLog(voteId,subjectId,itemId,devicesId,deleteFlag,createAt,createUser,updateAt,updateUser) SELECT a.voteId,:1,:2,:3,1,NOW(),:3,NOW(),:3 from voteSubject a where a.id=:1")
	void crtVoteLog(int subjectId, int itemId, String devicesId);

	@SQL("select count(1) from vote where deleteFlag=1 AND id=:1 AND now() < voteStart")
	int notStart(int voteId);

	@SQL("select count(1) from vote where deleteFlag=1 AND id=:1 AND voteStart < now() AND now() < voteEnd")
	int during(int voteId);

	@SQL("update voteItem set count=count+1 where id=:1")
	void addItmCnt(int itemId);
	
}
